//
//  IPVC.m
//  renyikan
//
//  Created by Steven on 2019/7/16.
//  Copyright © 2019 Steven. All rights reserved.
//

#import "IPVC.h"

@interface IPVC ()
@property(nonatomic,weak)IBOutlet UITextField *inputTF;

@property (weak, nonatomic) IBOutlet UILabel *countryLabel;

@property (weak, nonatomic) IBOutlet UILabel *provinceLabel;
@property (weak, nonatomic) IBOutlet UILabel *cityLabel;

@property (weak, nonatomic) IBOutlet UILabel *ispLabel;
@end

@implementation IPVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (IBAction)searchAction:(UIButton *)sender{
    [self.view endEditing:YES];
    
    if (self.inputTF.text.length == 0) {
        
        [MBProgressHUD showError:@"请输入IP地址！"];
        
        return;
    }
    
    __weak typeof(self) weakSelf = self;
    [JFNetworkingManager requestWithURLString:[NSString stringWithFormat:@"http://apis.juhe.cn/ip/ipNew?key=b2822ba99b1ecb34e2f9b611404df4bc&ip=%@",self.inputTF.text ] parameters:nil type:HttpRequestTypePost view:self.view success:^(id responseObject) {
        
        weakSelf.countryLabel.hidden = false;
        weakSelf.countryLabel.text = responseObject[@"result"][@"Country"];
        
        weakSelf.provinceLabel.hidden = false;
        weakSelf.provinceLabel.text = responseObject[@"result"][@"Province"];
        
        weakSelf.cityLabel.hidden = false;
        weakSelf.cityLabel.text = responseObject[@"result"][@"City"];
        
        weakSelf.ispLabel.hidden = false;
        weakSelf.ispLabel.text = responseObject[@"result"][@"Isp"];
        
    } failure:^(NSError *error) {
        
    }];
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}


@end
